laravel blade components

89

@foreach ($users as $user)
    @if ($loop->first)
        This is the first iteration.
    @endif

    @if ($loop->last)
        This is the last iteration.
    @endif

    <p>This is user {{ $user->id }}</p>
@endforeach
// Create component in terminal using :
	php artisan make:component MyComponent
  
// 2 files will be made : 
// * app\View\Components\MyComponent.php 
//   - Handels functionality.
// * resources\views\components\my-component.blade.php ()
//   - Code snippet for component. Must be inside <div>...</div>.
  	
// Call component in any other blade file using :
	<x-my-component />

// Send hardcoded parameter :
    <x-my-component name="Hello World!"/>

// Send a php parameter :
    <x-my-component :text="$message"/>

Comments

Submit
0 Comments